package com.guli.mall.pms.controller;

import java.util.Arrays;
import java.util.Map;

import com.guli.mall.pms.entity.vo.SkuInfoWithMinMaxPriceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;

import com.guli.mall.pms.entity.SkuInfoEntity;
import com.guli.mall.pms.service.SkuInfoService;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;


/**
 * sku信息
 *
 * @author 罗俊华
 * @email 1007052116@qq.com
 * @date 2020-09-17 11:37:22
 */
@RestController
@RequestMapping("pms/skuinfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;


    @PostMapping("/list/{currentPage}/{size}")
    @ApiOperation("根据当前页和每页显示的记录数来获取skuInfo分页列表")
    public R list(@PathVariable("currentPage") Integer currentPage, @PathVariable("size") Integer size,
                  @RequestBody SkuInfoWithMinMaxPriceVo skuInfoWithMinMaxPriceVo) {

        PageUtils<SkuInfoEntity> page = skuInfoService.queryPageByCondition(currentPage, size,skuInfoWithMinMaxPriceVo);

        return R.ok().put("page", page);
    }


    @GetMapping("/info/{skuId}")
    @ApiOperation("根据skuId获取SkuInfo")
    public R info(@PathVariable("skuId") Long skuId) {
        SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        return R.ok().put("skuInfo", skuInfo);
    }

    @GetMapping("/getInfoAndReturnTo/{skuId}")
    @ApiOperation("根据skuId获取SkuInfo")
    public SkuInfoEntity getInfoAndReturnTo(@PathVariable("skuId") Long skuId) {
        SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        return skuInfo;
    }

    @PostMapping("/save")
    @ApiOperation("插入SkuInfo")
    public R save(@RequestBody SkuInfoEntity skuInfoEntity) {
        skuInfoService.save(skuInfoEntity);

        return R.ok();
    }

    @PostMapping("/update")
    @ApiOperation("根据skuId更新SkuInfo")
    public R update(@RequestBody SkuInfoEntity skuInfo) {
        skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    @PutMapping("/deleteBatch")
    @ApiOperation("根据skuId批量删除SkuInfo")
    public R delete(@RequestBody Long[] skuIds) {
        skuInfoService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

}
